package com.turnengine.client.global.translation.bean;

import com.javabi.common.locale.LanguageCountry;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Translation.
 */
public class Translation implements ITranslation, Comparable<ITranslation> {

	/** The id. */
	private int id = 0;
	/** The text. */
	private String text = "";
	/** The language. */
	private LanguageCountry language = LanguageCountry.ENGLISH_UNITED_KINGDOM;

	/**
	 * Creates a new Translation.
	 */
	public Translation() {
	}

	/**
	 * Creates a new Translation.
	 * @param id the id
	 * @param text the text
	 * @param language the language
	 */
	public Translation(int id, String text, LanguageCountry language) {
		setId(id);
		setText(text);
		setLanguage(language);
	}

	/**
	 * Creates a new Translation.
	 * @param translation the translation
	 */
	public Translation(Translation translation) {
		setId(translation.getId());
		setText(translation.getText());
		setLanguage(translation.getLanguage());
	}

	/**
	 * Creates a new Translation.
	 * @param iTranslation the i translation
	 */
	public Translation(ITranslation iTranslation) {
		setId(iTranslation.getId());
		setText(iTranslation.getText());
		setLanguage(iTranslation.getLanguage());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the text.
	 * @return the text.
	 */
	public String getText() {
		return text;
	}

	/**
	 * Returns the language.
	 * @return the language.
	 */
	public LanguageCountry getLanguage() {
		return language;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the text.
	 * @param text the text to set.
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * Sets the language.
	 * @param language the language to set.
	 */
	public void setLanguage(LanguageCountry language) {
		this.language = language;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(191, 37);
		hash.append(id);
		hash.append(text);
		hash.append(language);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Translation) {
			Translation compare = (Translation) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.text, compare.text);
			equals.append(this.language, compare.language);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ITranslation compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.text, compare.getText());
		builder.append(this.language, compare.getLanguage());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (text != null) {
			string.append("text", text);
		}
		if (language != null) {
			string.append("language", language);
		}
		return string.toString();
	}
}
